package cn.stronglink.assetmanage.business.inventory.presenter;

import android.os.Bundle;

import java.util.List;
import java.util.Map;

import cn.stronglink.assetmanage.MainActivity;
import cn.stronglink.assetmanage.business.inventory.model.InventoryCountModel;
import cn.stronglink.assetmanage.business.inventory.view.count.InventoryCountView;
import cn.stronglink.assetmanage.entity.Inventory;
import cn.stronglink.assetmanage.entity.InventoryDetail;
import cn.stronglink.assetmanage.index.entity.PromissionEntity;
import cn.stronglink.assetmanage.utils.Constants;

/**
 * Created by chencongcong on 2018/6/15.
 */

public class InventoryCountPresenter {
    private InventoryCountModel inventoryCountModel;
    private InventoryCountView inventoryCountView;
    //盘点表单列表
    private List<Inventory> inventoryList;
    //盘点资产二级列表
    private Map<String, List<InventoryDetail>> itemDetailList;
    //选择的表单
    private Inventory inventory;

    public InventoryCountPresenter(InventoryCountModel inventoryCountModel, InventoryCountView inventoryCountView) {
        this.inventoryCountModel = inventoryCountModel;
        this.inventoryCountView = inventoryCountView;
    }

    /**
     * 初始化未盘点表单列表
     */
    public void initInventoryListView() {
        inventoryList = inventoryCountModel.getDataByOrderNoDistince();
        inventoryCountView.showListView();
        inventoryCountView.setListData(inventoryList);
    }

    /**
     * 根据点击位置显示资产列表
     *
     * @param position
     */
    public void showOrderByPosition(int position) {
//        inventory = inventoryList.get(position);
//        inventoryCountView.showAssetView();
//        itemDetailList = inventoryCountModel.getDataByOrderNo(inventory.getId_());
//        inventoryCountView.setAssetData(itemDetailList);
        MainActivity activity = (MainActivity) this.inventoryCountView.getFragment().getActivity();
        PromissionEntity pe = new PromissionEntity();
        pe.setPosition(MainActivity.FRAGMENT_INVENTORY_DETAIL_ID);

        // 设置打开盘点详情后传递的参数
        inventory = inventoryList.get(position);
        Bundle bundle=new Bundle();
        bundle.putSerializable(Constants.INVENTORY_DETAIL_NO, inventory.getId_());
        pe.setBundle(bundle);

        activity.onEventRegister(pe);
    }

    public void showDetailByPosition(String groupName, int childPosition) {
        InventoryDetail inventoryDetail = itemDetailList.get(groupName).get(childPosition);
        inventoryCountView.showOrderDetail(inventoryDetail);
    }

    public void showOrderDataByOrderId(String orderNo) {
        inventory = inventoryCountModel.getInventoryByOrderNo(orderNo);
        inventoryCountView.showAssetView();
        itemDetailList = inventoryCountModel.getDataByOrderNo(orderNo);
        inventoryCountView.setAssetData(itemDetailList);
    }
}
